package com.selftcp;

import java.net.InetAddress;
import java.util.Objects;

//连接标识类，用于唯一区分一个TCP连接
public class ConnectionKey {
	
	private final InetAddress clientAddr;
    private final int clientPort;

    public ConnectionKey(InetAddress clientAddr, int clientPort) {
        this.clientAddr = clientAddr;
        this.clientPort = clientPort;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ConnectionKey that = (ConnectionKey) o;
        return clientPort == that.clientPort && Objects.equals(clientAddr, that.clientAddr);
    }

    @Override
    public int hashCode() {
        return Objects.hash(clientAddr, clientPort);
    }

}
